#include <bits/stdc++.h>
#ifndef DEBUG
#define debug
#endif
using namespace std;
using i64 = int64_t;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n, x;
  cin >> n >> x;
  vector<pair<int, int>> a;
  for (int i = 1; i <= n; i ++) {
    int y;
    cin >> y;
    a.emplace_back(y, i);
  }
  for (int i = 1; i <= n; i ++) {
    int y;
    cin >> y;
    a.emplace_back(y, -i);
  }
  a.emplace_back(x, 0);
  a.emplace_back(0, 0);
  sort(a.begin(), a.end());
  vector<int> key(n + 1);
  n = a.size();
  for (int i = 0; i < n; i ++) {
    if (a[i].second < 0) key[-a[i].second] = i;
  }
  const i64 inf = LLONG_MAX / 2;
  vector<vector<array<i64, 2>>> dp(n, vector<array<i64, 2>>(n, {inf, inf}));
  i64 ans = inf;
  for (int l = n - 1; l >= 0; l --) {
    if (a[l].second == 0 && a[l].first == 0) dp[l][l][0] = dp[l][l][1] = 0;
    for (int r = l + 1; r < n; r ++) {
      if ((a[l].second > 0 && l + 1 <= key[a[l].second] && key[a[l].second] <= r) || a[l].second <= 0) {
        dp[l][r][0] = min(
          dp[l+1][r][0] + abs(a[l].first - a[l + 1].first),
          dp[l+1][r][1] + abs(a[l].first - a[r].first)
        );
      }
      if ((a[r].second > 0 && l <= key[a[r].second] && key[a[r].second] <= r - 1) || a[r].second <= 0) {
        dp[l][r][1] = min(
          dp[l][r-1][0] + abs(a[r].first - a[l].first),
          dp[l][r-1][1] + abs(a[r].first - a[r - 1].first)
        );
      }
      if (dp[l][r][0] != inf && a[l].first == x) ans = min(ans, dp[l][r][0]);
      if (dp[l][r][1] != inf && a[r].first == x) ans = min(ans, dp[l][r][1]);
    }
  }
  if (ans == inf) cout << -1 << endl;
  else cout << ans << endl;
}